package views.features;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import views.util.CalendarPanel;
import views.util.GameColors;

public class ChronologyView extends FeatureView {

	private CalendarPanel calendar;
	private JTextArea chronology;// E' il riquadro in basso in cui verranno
									// mostrate le attività del giorno
									// selezionato
	private static ChronologyView instance;

	private ChronologyView() {
		setLayout(new BorderLayout());
		calendar = new CalendarPanel();
		add(calendar, BorderLayout.CENTER);
		chronology = new JTextArea();
		chronology.setBackground(GameColors.BLU);
		chronology.setForeground(Color.WHITE);
		Font font = new Font("Segoe UI", Font.ITALIC, 22);
		Dimension size = new Dimension(800, 250);
		chronology.setLineWrap(true);
		chronology.setMaximumSize(size);
		chronology.setFont(font);
		chronology.setText("Clicca su un giorno per vederne la cronologia");
		chronology.setEditable(false);
		chronology.setAlignmentY(CENTER_ALIGNMENT);
		JScrollPane scroll = new JScrollPane(chronology);
		scroll.setPreferredSize(size);
		add(scroll, BorderLayout.SOUTH);
	}

	public static ChronologyView newInstance() {
		if (instance == null)
			instance = new ChronologyView();
		return instance;
	}

	public void addActionListenerToTheDays(ActionListener a) {
		System.out.println(calendar.getDayButtons().size());
		for (JButton b : calendar.getDayButtons())
			b.addActionListener(a);
	}

	public void updateChronology(String[] s) {
		StringBuilder sb = new StringBuilder();
		for (String st : s) {
			sb.append(st + "\n");
		}
		sb.append("\n\n");
		chronology.setText(sb.toString());
	}

}
